//
//  YProgressDialog.swift
//  EasyEverything
//
//  Created by YangZhe on 17/1/23.
//  Copyright © 2017年 kuletech. All rights reserved.
//

import UIKit

open class YProgressDialog:NSObject{
    static var progressDialog:SVProgressHUD?
    static var progressDialog2:MBProgressHUD?
    
    @objc open class func showProgress(viewController:YUIViewController){
        if viewController.isAlive {
            SVProgressHUD.dismiss()
            SVProgressHUD.setDefaultMaskType(.black)
            SVProgressHUD.setDefaultStyle(.light)
            SVProgressHUD.show(withStatus: "拼命加载中···")
            self.changeEnable(viewController: viewController, enable: false)
        }
    }
    
    @objc open class func dismissProgress(viewController:YUIViewController){
        SVProgressHUD.dismiss()
        self.changeEnable(viewController: viewController, enable: true)
    }
    
    @objc open class func showProgress2(viewController:YUIViewController){
        if viewController.isAlive {
            progressDialog2?.removeFromSuperview()
            progressDialog2 = MBProgressHUD(view: viewController.view)
            progressDialog2!.bezelView.backgroundColor = YConfig.progressColor.withAlphaComponent(0.2)
            progressDialog2!.label.text = "拼命加载中···"
            progressDialog2!.label.textColor = YConfig.progressColor
            for view in progressDialog2!.bezelView.subviews {
                if view is UIActivityIndicatorView{
                    (view as! UIActivityIndicatorView).color = YConfig.progressColor
                    break
                }
            }
            viewController.view.addSubview(progressDialog2!)
            progressDialog2!.show(animated: true)
            self.changeEnable(viewController: viewController, enable: false)
        }
    }
    
    @objc open class func dismissProgress2(viewController:YUIViewController){
        progressDialog2?.removeFromSuperview()
        progressDialog2 = nil
        self.changeEnable(viewController: viewController, enable: true)
    }
    
    private class func changeEnable(viewController:YUIViewController,enable:Bool){
        viewController.view.isUserInteractionEnabled = enable
        viewController.navigationController?.view.isUserInteractionEnabled = enable
        viewController.tabBarController?.view.isUserInteractionEnabled = enable
    }
}
